using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DartsDetector.Classes.Games.Base;
using DartsDetector.Classes.Games;
using DartsDetector.Classes;
using DartsDetector.CustomCtrls;

namespace DartsDetector
{
    public partial class Form1 : Form
    {
        private const int MAX_PLAYERS = 4;
        GameBase _Game;

        public Form1()
        {
            InitializeComponent();

			frmDevCalc frm = new frmDevCalc();
			frm.ShowDialog();
        }

        private void StartNewGame(Game gameType)
        {
            switch (gameType)
            {
                case Game.Game301:
                    //_Game = new Game301();
                    break;
                case Game.Game501:
                    _Game = new Game501();
                    break;
                case Game.MickeyMouse:
                    //_Game = new GameMickeyMouse();
                    break;
            }

            for (int i = _Game.NumberOfPlayers; i <= MAX_PLAYERS; i++)
            {
                GroupBox pnl = (GroupBox)Utils.GetControlRecursive("gbPlayer" + (i + 1), this);
                if (pnl != null)
                    pnl.Visible = false;
            }

            flpPlayers.SuspendLayout();
            for (int i = 0; i < _Game.NumberOfPlayers; i++)
            {
                PlayerGroupBox pgb = new PlayerGroupBox();                
                flpPlayers.Controls.Add(pgb);
            }
            flpPlayers.ResumeLayout();
        }



        private void DartThrown(int score)
        {
            _Game.DartThrown(score);
            UpdateLabels();
        }

        private void UpdateLabels()
        {
            lbCurrentPlayer.Text = String.Format(Resource1.PlayerToThrow, "Hassan" + _Game.ActivePlayerIndex);
            /*
            for (int iPlayer = 0; iPlayer < _Game.NumberOfPlayers; iPlayer++)
            {
                Label lbScore = (Label)Utils.GetControlRecursive("lbScorePlayer" + (iPlayer + 1), this);
                lbScore.Text = (_Game.BeginScore - _Game.PlayerTurns[iPlayer].TotalScore).ToString();

                for (int iDart = 0; iDart < 3; iDart++)
                {
                    Label lblDart = (Label)Utils.GetControlRecursive("lbDart" + (iDart + 1) + "Player" + (iPlayer + 1), this);
                    if (lblDart != null)
                        lblDart.Text = (_Game.PlayerThrows[iPlayer].DartScores.Count > iDart) ? _Game.PlayerThrows[iPlayer].DartScores[iDart].ToString() : "-";
                }
            }*/
        }



        #region Dev buttons
        private void startGameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StartNewGame(Game.Game501);
            UpdateLabels();
        }

        private void throwDartToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Random rand = new Random();
            int score = rand.Next(60);

            DartThrown(score);
        }
        #endregion

        
		private void showCamDevToolStripMenuItem_Click(object sender, EventArgs e)
		{
			frmDevCalc frm = new frmDevCalc();
			frm.Show();
		}
    }
}